package com.lingx.model.impl.interpreter;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Component;

import com.lingx.model.impl.AbstractInterpreter;
@Component
public class TimeStampInterpreter  extends AbstractInterpreter{

	private static final long serialVersionUID = 5538876628740005029L;

	public TimeStampInterpreter() {
		super("TimeStampInterpreter","秒级时间戳转yyyy-MM-dd HH:mm:ss");
	}
	@Override
	public Object input(Object value) throws Exception {
		String datetime=value.toString();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=sdf.parse(datetime);
		return date.getTime()/1000;
	}

	@Override
	public Object output(Object value) throws Exception {

		long ts=Long.parseLong(value.toString());
		Date date=new Date(ts*1000);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	//System.out.println(sdf.format(date));
		return sdf.format(date);
	}
	
	public static void main(String args[]) {
		//1648280763352
		//1647855378
		System.out.println(System.currentTimeMillis());
		Date date=new Date(1647855378l*1000);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println(sdf.format(date));
	}

}
